ig.module(
    
    'game.entities.shooter'
    
).requires(
    
    'impact.entity',
    'game.entities.moveable',
    'game.entities.bullit',
    'game.entities.particle'
    
).defines(function(){

    EntityShooter = Moveable.extend({
        size:{
            x: 16,
            y: 16
        },
        offset:{
            x: 0,
            y: 0
        },
        maxVel: {
            x: 250,
            y: 250
        },
        moveclass: ig.movement.InsideRadiusMovement.extend({            
            center: {
                x: 50,
                y: 50
            },
            vel: {
                x: 10,
                y: 10
            },
            centerstep: {
                x: 4,
                y: 4
            },
            radius: 50
        }),
        player: null,        
        type: ig.Entity.TYPE.B,        
        checkAgainst: ig.Entity.TYPE.A,        
        health: 50,        
        animSheet: new ig.AnimationSheet('media/sprites/factory.png',16,16),
        
        init: function( x, y, settings){
            this.parent(x, y, settings);
            this.addAnim('idle', 1, [0]);           

            this.shootTimer = new ig.Timer();

        },
        update: function(){            
            if( this.shootTimer.delta() > 5 ){
                this.shootTimer.set( 0 );                
                var dx = (this.player.pos.x - (this.pos.x + this.size.x/2));
                var dy = (this.player.pos.y - (this.pos.y + this.size.y/2));
                ig.game.spawnEntity( EntityBullit, this.pos.x, this.pos.y, {
                    type: ig.Entity.TYPE.B,        
                    checkAgainst: ig.Entity.TYPE.A, 
                    moveclass: ig.movement.LinearMovement.extend({
                        vel: ig.VUtils.scaleToLen({x: dx, y: dy}, 100),
                        accel: ig.VUtils.scaleToLen({x: dx, y: dy}, 50)
                    })
                });
            }
            this.parent();
        },
        check: function( other ){
            this.kill();
            other.receiveDamage( 10 );
        },
        kill: function(){
            var gibs = ig.ua.mobile ? 5 : 30;
            for (var i = 0; i < gibs; i++) {
                ig.game.spawnEntity(EntityFollowerGib, this.pos.x, this.pos.y);
            }
            this.parent();
        }
    });
    
    EntityShooterGib = EntityParticle.extend({
        lifetime: 3,
        fadetime: 6,
        friction: {
            x: 0,
            y: 0
        },
        vel: {
            x: 60,
            y: 150
        },
        animSheet: new ig.AnimationSheet('media/sprites/blob-gibs.png', 4, 4),
        init: function (x, y, settings) {
            this.addAnim('idle', 0.1, [0, 1, 2]);
            this.parent(x, y, settings);
        }
    });
});